package com.ruoyi.server.api.memberTypeManagement.controller;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.exception.errorCode.CommonException;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.server.api.memberTypeManagement.domain.MemberTypeManagement;
import com.ruoyi.server.api.memberTypeManagement.service.IMemberTypeManagementService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;
import java.util.List;
/**
 * 会员类型Controller
 * 
 * @author ruoyi
 * @date 2024-06-10
 */
@RestController
@RequestMapping("/memberTypeManagement/management")
public class MemberTypeManagementController extends BaseController
{
    @Autowired
    private IMemberTypeManagementService memberTypeManagementService;
    /**
     * 查询会员类型列表
     */
    @PreAuthorize("@ss.hasPermi('memberTypeManagement:management:list')")
    @GetMapping("/memberTypeManagementList")
    public TableDataInfo list(MemberTypeManagement memberTypeManagement)
    {
        startPage();
        List<MemberTypeManagement> list = memberTypeManagementService.selectMemberTypeManagementList(memberTypeManagement);
        return getDataTable(list);
    }
    /**
     * 导出会员类型列表
     */
    @PreAuthorize("@ss.hasPermi('memberTypeManagement:management:export')")
    @Log(title = "会员类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberTypeManagement memberTypeManagement)
    {
        List<MemberTypeManagement> list = memberTypeManagementService.selectMemberTypeManagementList(memberTypeManagement);
        ExcelUtil<MemberTypeManagement> util = new ExcelUtil<MemberTypeManagement>(MemberTypeManagement.class);
        util.exportExcel(response, list, "会员类型数据");
    }
    /**
     * 获取会员类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('memberTypeManagement:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(memberTypeManagementService.selectMemberTypeManagementById(id,null));
    }
    /**
     * 新增会员类型
     */
    @PreAuthorize("@ss.hasPermi('memberTypeManagement:management:add')")
    @Log(title = "会员类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberTypeManagement memberTypeManagement) throws CommonException {
        return toAjax(memberTypeManagementService.insertMemberTypeManagement(memberTypeManagement));
    }
    /**
     * 修改会员类型
     */
    @PreAuthorize("@ss.hasPermi('memberTypeManagement:management:edit')")
    @Log(title = "会员类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberTypeManagement memberTypeManagement) throws CommonException {
        return toAjax(memberTypeManagementService.updateMemberTypeManagement(memberTypeManagement));
    }
    /**
     * 修改会员卡状态
     */
    @PreAuthorize("@ss.hasPermi('memberTypeManagement:management:edit')")
    @Log(title = "会员类型", businessType = BusinessType.UPDATE)
    @PutMapping("/editState")
    public AjaxResult editState(@RequestBody MemberTypeManagement memberTypeManagement) throws CommonException {
        return toAjax(memberTypeManagementService.updateMemberTypeManagementState(memberTypeManagement));
    }
    /**
     * 删除会员类型
     */
    @PreAuthorize("@ss.hasPermi('memberTypeManagement:management:remove')")
    @Log(title = "会员类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/deleteMemberTypeManagement")
    public AjaxResult remove(@RequestBody MemberTypeManagement memberTypeManagement) throws CommonException {
        return toAjax(memberTypeManagementService.deleteMemberTypeManagementById(memberTypeManagement));
    }
}
